<?php

require_once ("memberModel.php");
require_once ("boatModel.php");
require_once ("dbModel.php");

class FacadeModel {

	private $m_memberModel;
	private $m_boatModel;

	public function __construct() {
		$db = new DbModel();
		$this -> m_boatModel = new BoatModel($db);
		$this -> m_memberModel = new MemberModel($db, $this -> m_boatModel);
	}

	public function addMember($a_userInfo) {
		$this -> m_memberModel -> create($a_userInfo);
	}

	public function addBoat($a_boatInfo) {
		$this -> m_boatModel -> create($a_boatInfo);
	}

	public function getMembers() {
		return $this -> m_memberModel -> read();
	}

	public function getMember($a_memberId) {
		$returnArray = $this -> m_memberModel -> read($a_memberId);
		return $returnArray[0];
	}

	public function getBoat($a_boatId) {
		$returnArray = $this -> m_boatModel -> read($a_boatId);
		return $returnArray[0];
	}

	public function saveMember($a_memberInfo) {
		$this -> m_memberModel -> update($a_memberInfo);
	}

	public function saveBoat($a_boatInfo) {
		$this -> m_boatModel -> update($a_boatInfo);
	}

	public function removeMember($a_memberId) {
		$this -> m_memberModel -> delete($a_memberId);
	}

	public function removeBoat($a_boatId) {
		$this -> m_boatModel -> delete($a_boatId);
	}

	public function logInMember($a_userName, $a_passWord) {
		$compareMember = reset($this -> m_memberModel -> read($a_userName, 'name'));
		
		if(is_object($compareMember)) {
		
			if ($compareMember -> password === $a_passWord) {
				return true;
			}
		}
		return false;
	}

}
